package com.bwie.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.mapper.CouponMapper;
import com.bwie.mapper.TbBuyMapper;
import com.bwie.mapper.TbLogMapper;
import com.bwie.mapper.TbSellMapper;
import com.bwie.pojo.TbBuy;
import com.bwie.pojo.TbLog;
import com.bwie.pojo.TbSell;
import com.bwie.pojo.couponCode;
import com.bwie.service.CouponService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.couponCodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CouponServiceImpl implements CouponService {
    @Autowired
    CouponMapper couponMapper;
    @Autowired
    TbSellMapper tbSellMapper;
    @Autowired
    TbBuyMapper tbBuyMapper;
    @Autowired
    TbLogMapper tbLogMapper;

    @Override
    public R selectCoupon(couponCodeVo couponCodeVo) {
        Page<couponCode> page = new Page<>(couponCodeVo.getPageNum(),couponCodeVo.getPageSize());
        Page<couponCode> couponCodePage = couponMapper.selectPage(page, new QueryWrapper<>());

        return R.OK(couponCodePage);
    }

    @Override
    public R couPonAdd(couponCode couponCode) {
        int insert = couponMapper.insert(couponCode);
        return R.OK(insert);
    }

    @Override
    public R selectSell(PageInfoVo pageInfoVo) {
        Page<TbSell> page = new Page<>(pageInfoVo.getPageNum(),pageInfoVo.getPageSize());
        Page<TbSell> selectPage = tbSellMapper.selectPage(page, new QueryWrapper<>());
        return R.OK(selectPage);
    }

    @Override
    public R selectBuy(PageInfoVo pageInfoVo) {
        Page<TbBuy> page = new Page<>(pageInfoVo.getPageNum(),pageInfoVo.getPageSize());
        Page<TbBuy> selectPage = tbBuyMapper.selectPage(page, new QueryWrapper<>());
        return R.OK(selectPage);
    }
    /**
     * @Author: huliwen
     * @Date: 2025/5/19 15:35
     * 订单分页
     */
    @Override
    public R selectLog(PageInfoVo pageInfoVo) {
        Page<TbLog> page = new Page<>(pageInfoVo.getPageNum(),pageInfoVo.getPageSize());
        Page<TbLog> selectPage = tbLogMapper.selectPage(page, new QueryWrapper<>());
        return R.OK(selectPage);
    }

    @Override
    public R updateLogs(TbLog tbLog) {
        tbLog.setLogStatus(0);
        return R.OK();
    }
}
